Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    encode: {
      type: String,
      value: ''
    },
    width: {
      type: Number,
      value: 240
    },
    height: {
      type: Number,
      value: 427
    }
  },
  data: {},

  methods: {
    close () {
      this.setData({ show: false })
    },

    savePoster() {
      const encode = this.data.encode;
      var save = wx.getFileSystemManager();
      var number = Math.random();
      save.writeFile({
        filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg',
        data: encode.slice(22),
        encoding: 'base64',
        success: res => {
          wx.saveImageToPhotosAlbum({
            filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg',
            success: (res) => {
              this.setData({
                show: false
              });
              wx.showToast({
                title: '保存成功',
              })
            },
            fail: (err) => {
              console.log(err)
            }
          })
        },
        fail: err => {
          console.log(err)
        }
      })
      // let that = this;
      // wx.downloadFile({
      //   url: this.data.url,
      //   success: function (res) {
      //     if (res.statusCode === 200) {
      //       let img = res.tempFilePath;
      //       wx.saveImageToPhotosAlbum({
      //         filePath: img,
      //         success(res) {
      //           app.toast('保存成功');
      //         }
      //       });
      //     }
      //   }
      // });
    }
  }
})